package Gui;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import DAO.*;
/**
*
* @author acer
*/
public class StuLogin extends javax.swing.JFrame {

   /**
    * Creates new form StuLogin
    */
   public StuLogin() {
       initComponents();
   }

   /**
    * This method is called from within the constructor to initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is always
    * regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
   private void initComponents() {

	   jPanel= new javax.swing.JPanel() {
       	public void paintComponent(Graphics g) {
           	ImageIcon icon=new ImageIcon("image/背景.jpg");
           	Image img = icon.getImage();
           	g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this);
           }
       };
       jLabel1 = new javax.swing.JLabel();
       jLabel2 = new javax.swing.JLabel();
       jLabel3 = new javax.swing.JLabel();
       username = new javax.swing.JTextField();
       password = new javax.swing.JPasswordField();
       register = new javax.swing.JButton();
       back = new javax.swing.JButton();
       login = new javax.swing.JButton();

       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

       jLabel1.setFont(new java.awt.Font("华文行楷", 0, 36)); // NOI18N
       jLabel1.setText("学生系统");
       jLabel1.setToolTipText("");

       jLabel2.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
       jLabel2.setText("账号");

       jLabel3.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
       jLabel3.setText("密码");

       username.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               usernameActionPerformed(evt);
           }
       });

       register.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
       register.setText("注册账号");
       register.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               registerActionPerformed(evt);
           }
       });

       back.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
       back.setText("忘记密码");
       back.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) 
           {
               backActionPerformed(evt);
           }
       });

       login.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
       login.setText("登录");
       login.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               loginActionPerformed(evt);
           }
       });

       javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(jPanel);
       jPanel.setLayout(jPanelLayout);
       jPanelLayout.setHorizontalGroup(
           jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(jPanelLayout.createSequentialGroup()
               .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(jPanelLayout.createSequentialGroup()
                       .addGap(106, 106, 106)
                       .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE))
                   .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelLayout.createSequentialGroup()
                       .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                           .addGroup(jPanelLayout.createSequentialGroup()
                               .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                               .addComponent(login, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                           .addGroup(jPanelLayout.createSequentialGroup()
                               .addGap(27, 27, 27)
                               .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jLabel2)
                                   .addComponent(jLabel3))
                               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                               .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))))
                       .addGap(24, 24, 24)))
               .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(jPanelLayout.createSequentialGroup()
                       .addComponent(register, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                       .addGap(0, 0, Short.MAX_VALUE))
                   .addComponent(back, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
               .addContainerGap())
       );
       jPanelLayout.setVerticalGroup(
           jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(jPanelLayout.createSequentialGroup()
               .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
               .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(register, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(18, 18, 18)
               .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(back, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(31, 31, 31)
               .addComponent(login)
               .addGap(0, 35, Short.MAX_VALUE))
       );

       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
       layout.setHorizontalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
       );
       layout.setVerticalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
       );

       pack();
       setLocationRelativeTo(null);

   }// </editor-fold>                        

   private void usernameActionPerformed(java.awt.event.ActionEvent evt) {                                         
       // TODO add your handling code here:
   }                                        

   private void registerActionPerformed(java.awt.event.ActionEvent evt) {                                         
       JOptionPane.showMessageDialog(null, "密码与用户名相同即可");
   }                                        

   private void backActionPerformed(java.awt.event.ActionEvent evt) {                                     
       JOptionPane.showMessageDialog(null, "密码与用户名相同即可");
   }                                    

   private void loginActionPerformed(java.awt.event.ActionEvent evt) {                                      
       String num=username.getText();
       String p=password.getText();
       int x=new Identify().Passwordquthentification(num,p);//登陆验证
       if(x==1){
           JOptionPane.showMessageDialog(null, "登陆成功！");
           this.setVisible(false);
           new Stufunction().setVisible(true);
       }
       else if(x==0){
           JOptionPane.showMessageDialog(null,"密码错误！请重新输入","登录提示" , JOptionPane.ERROR_MESSAGE);
       }
   }                                     

   /**
    * @param args the command line arguments
    */
   public static void main(String args[]) {
       /* Set the Nimbus look and feel */
       //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
       /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
        * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
        */
       try {
           for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
               if ("Nimbus".equals(info.getName())) {
                   javax.swing.UIManager.setLookAndFeel(info.getClassName());
                   break;
               }
           }
       } catch (ClassNotFoundException ex) {
           java.util.logging.Logger.getLogger(StuLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (InstantiationException ex) {
           java.util.logging.Logger.getLogger(StuLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (IllegalAccessException ex) {
           java.util.logging.Logger.getLogger(StuLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (javax.swing.UnsupportedLookAndFeelException ex) {
           java.util.logging.Logger.getLogger(StuLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       }
       //</editor-fold>

       /* Create and display the form */
       java.awt.EventQueue.invokeLater(new Runnable() {
           public void run() {
               new StuLogin().setVisible(true);
           }
       });
   }

   // Variables declaration - do not modify                     
   private javax.swing.JButton back;
   private javax.swing.JLabel jLabel1;
   private javax.swing.JLabel jLabel2;
   private javax.swing.JLabel jLabel3;
   private javax.swing.JPanel jPanel;
   private javax.swing.JButton login;
   private javax.swing.JTextField password;
   private javax.swing.JButton register;
   private javax.swing.JTextField username;
   // End of variables declaration                   
}

